package com.sanpu.kxe.business.main.view;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sanpu.kxe.R;
import com.sanpu.kxe.base.BaseTitleActivity;
import com.sanpu.kxe.business.main.adapter.CreditEventAdapter;
import com.sanpu.kxe.business.main.bean.CreditEventOutput;
import com.sanpu.kxe.business.main.contract.CreditEventContract;
import com.sanpu.kxe.business.main.presenter.CreditEventPresenter;

import java.util.List;

import butterknife.Bind;

/**
 * Description：信用卡活动
 * Created by 薛勇军 on 2019/4/1.
 */
@Route(path = "/main/CreditEventAct")
public class CreditEventActivity extends BaseTitleActivity implements CreditEventContract.View {

    @Bind(R.id.recycler_view)
    RecyclerView vRecyclerview;
    @Bind(R.id.emptyView)
    View emptyView;

    private CreditEventAdapter mCenterAdapter;

    private CreditEventContract.Presenter mPresenter;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_event_center;
    }

    @Override
    protected void initView() {
        super.initView();
        commonTitle.setTitle("信用卡活动");

        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
        vRecyclerview.setLayoutManager(layoutManager);

        mCenterAdapter = new CreditEventAdapter(mContext);
        vRecyclerview.setAdapter(mCenterAdapter);
        mPresenter = new CreditEventPresenter(this);
        mPresenter.creditcardActList();
    }

    @Override
    protected void setListener() {
        super.setListener();
        mCenterAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                CreditEventOutput output = ((CreditEventAdapter) adapter).getItem(position);
                if (output != null) {
                    mPresenter.onItemClick(output);
                }
            }
        });
    }

    @Override
    public void showDataView(List<CreditEventOutput> outputs) {
        if (outputs != null && outputs.size() > 0) {
            vRecyclerview.setVisibility(View.VISIBLE);
            emptyView.setVisibility(View.GONE);
            mCenterAdapter.setNewData(outputs);
        } else {
            vRecyclerview.setVisibility(View.GONE);
            emptyView.setVisibility(View.VISIBLE);
        }
    }

    @Override
    protected boolean hasBindEventBus() {
        return false;
    }

    @Override
    public void setPresenter(CreditEventContract.Presenter presenter) {
        this.mPresenter = presenter;
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.onDestroyPresenter();
            mPresenter = null;
        }
    }
}
